package com.lzy.product.service.impl;

import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.dao.AgentMemberProtocolMapper;
import com.lzy.product.dao.AgentMemberProtocolMapperExt;
import com.lzy.product.dtos.agent.AgentMemberProtocolDto;
import com.lzy.product.entity.AgentMemberProtocol;
import com.lzy.product.service.AgentMemberProtocolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgentMemberProtocolServiceImpl implements AgentMemberProtocolService {

    @Autowired
    private AgentMemberProtocolMapper agentMemberProtocolMapper;

    @Autowired
    private AgentMemberProtocolMapperExt agentMemberProtocolMapperExt;

    @Override
    public Long insert(AgentMemberProtocolDto dto) {
        AgentMemberProtocol agentMemberProtocol = DozerUtils.map(dto, AgentMemberProtocol.class);
        return agentMemberProtocolMapper.insertSelective(agentMemberProtocol) > 0 ? agentMemberProtocol.getId() : 0;
    }

    @Override
    public Boolean update(AgentMemberProtocolDto dto) {
        return agentMemberProtocolMapper.updateByPrimaryKeySelective(DozerUtils.map(dto, AgentMemberProtocol.class)) > 0 ? true : false;
    }

    @Override
    public Boolean delete(Long id) {
        return agentMemberProtocolMapper.deleteByPrimaryKey(id) > 0 ? true : false;
    }

    @Override
    public Boolean remove(Long id) {
        return null;
    }

    @Override
    public AgentMemberProtocolDto findById(Long id) {
        AgentMemberProtocol agentMemberProtocol = agentMemberProtocolMapper.selectByPrimaryKey(id);
        return agentMemberProtocol == null ? null : DozerUtils.map(agentMemberProtocol, AgentMemberProtocolDto.class);
    }

    @Override
    public List<AgentMemberProtocolDto> query(AgentMemberProtocolDto dto) {
        List<AgentMemberProtocol> list = agentMemberProtocolMapperExt.selectByParam(dto);
        return list.isEmpty() ? null : DozerUtils.maps(list, AgentMemberProtocolDto.class);
    }
}
